package top.wilsonlv.jaguar.cloud.upms.service;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import top.wilsonlv.jaguar.cloud.auth.sdk.feign.RemoteArcFaceService;

/**
 * @author lvws
 * @since 2022/1/24
 */
@Service
@RequiredArgsConstructor
public class FaceService {

    private static final String DATA_IMAGE_PNG_BASE64 = "data:image/png;base64,";

    private final RemoteArcFaceService arcFaceService;

    public String face2Feature(String face) {
        if (!StringUtils.hasText(face)) {
            return null;
        }

        String faceBase64;
        if (face.startsWith(DATA_IMAGE_PNG_BASE64)) {
            faceBase64 = face.substring(DATA_IMAGE_PNG_BASE64.length());
        } else {
            faceBase64 = face;
        }

        return arcFaceService.check(faceBase64, true).getData();
    }

}
